<?php
class CollapsibleBlock extends Container {
	
	private $header;
	private $collapsed;
	private $contentDataTheme;
	
	public function __construct($elementId, Heading $header) {
		
		parent::__construct($elementId);
		
		$this->header = $header;
		$this->collapsed = TRUE;
		$this->dataTheme = NULL;
	}
	
	public function setCollapsed($collapsed) {
		
		$this->collapsed = $collapsed;
	}
	
	public function setContentDataTheme(DataTheme $contentDataTheme) {
		
		$this->contentDataTheme = $contentDataTheme;
	}
	
	protected function renderOpeningMarkup() {
		
		if ($this->collapsed == FALSE) {
			$this->addAttribute(new Attribute('data-collapsed', 'false'));
		}
		
		if ($this->contentDataTheme != NULL) {
			$this->addAttribute(new Attribute('data-content-theme', $this->contentDataTheme->getValue()));
		}
		
		echo '<div data-role="collapsible" ', $this->formatAttributes(), '>';
		$this->header->render();
	}
	
	protected function renderClosingMarkup() {
		
		echo '</div>';
	}
}
?>